using Easislides.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Easislides
{
	public class FrmRearrangeFolderPositions : Form
	{
		private IContainer components = null;
		private ListView SongFolder;
		private Button OKBtn;
		private Button CancelBtn;
		private ColumnHeader columnHeader1;
		private ToolStrip toolStripRearrangeFolders;
		private ToolStripButton SF_Up;
		private ToolStripButton SF_Down;
		private ColumnHeader columnHeader2;
		private Panel panel1;
		private int[] OriginalFolderPosition = new int[41];
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.SongFolder = new System.Windows.Forms.ListView();
            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.OKBtn = new System.Windows.Forms.Button();
            this.CancelBtn = new System.Windows.Forms.Button();
            this.toolStripRearrangeFolders = new System.Windows.Forms.ToolStrip();
            this.SF_Up = new System.Windows.Forms.ToolStripButton();
            this.SF_Down = new System.Windows.Forms.ToolStripButton();
            this.panel1 = new System.Windows.Forms.Panel();
            this.toolStripRearrangeFolders.SuspendLayout();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // SongFolder
            // 
            this.SongFolder.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2});
            this.SongFolder.FullRowSelect = true;
            this.SongFolder.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
            this.SongFolder.HideSelection = false;
            this.SongFolder.Location = new System.Drawing.Point(12, 12);
            this.SongFolder.Name = "SongFolder";
            this.SongFolder.ShowGroups = false;
            this.SongFolder.ShowItemToolTips = true;
            this.SongFolder.Size = new System.Drawing.Size(156, 209);
            this.SongFolder.TabIndex = 0;
            this.SongFolder.UseCompatibleStateImageBehavior = false;
            this.SongFolder.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "";
            this.columnHeader1.Width = 120;
            // 
            // columnHeader2
            // 
            this.columnHeader2.Width = 0;
            // 
            // OKBtn
            // 
            this.OKBtn.Location = new System.Drawing.Point(199, 21);
            this.OKBtn.Name = "OKBtn";
            this.OKBtn.Size = new System.Drawing.Size(80, 24);
            this.OKBtn.TabIndex = 1;
            this.OKBtn.Text = "Apply";
            this.OKBtn.Click += new System.EventHandler(this.OKBtn_Click);
            // 
            // CancelBtn
            // 
            this.CancelBtn.Location = new System.Drawing.Point(199, 51);
            this.CancelBtn.Name = "CancelBtn";
            this.CancelBtn.Size = new System.Drawing.Size(80, 24);
            this.CancelBtn.TabIndex = 2;
            this.CancelBtn.Text = "Cancel";
            this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
            // 
            // toolStripRearrangeFolders
            // 
            this.toolStripRearrangeFolders.AutoSize = false;
            this.toolStripRearrangeFolders.CanOverflow = false;
            this.toolStripRearrangeFolders.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStripRearrangeFolders.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStripRearrangeFolders.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.SF_Up,
            this.SF_Down});
            this.toolStripRearrangeFolders.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.VerticalStackWithOverflow;
            this.toolStripRearrangeFolders.Location = new System.Drawing.Point(0, 0);
            this.toolStripRearrangeFolders.Name = "toolStripRearrangeFolders";
            this.toolStripRearrangeFolders.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolStripRearrangeFolders.Size = new System.Drawing.Size(25, 57);
            this.toolStripRearrangeFolders.TabIndex = 0;
            // 
            // SF_Up
            // 
            this.SF_Up.AutoSize = false;
            this.SF_Up.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.SF_Up.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.SF_Up.Name = "SF_Up";
            this.SF_Up.Size = new System.Drawing.Size(22, 22);
            this.SF_Up.Tag = "up";
            this.SF_Up.ToolTipText = "Move Item Up";
            this.SF_Up.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SF_UpDown_MouseUp);
            // 
            // SF_Down
            // 
            this.SF_Down.AutoSize = false;
            this.SF_Down.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.SF_Down.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.SF_Down.Name = "SF_Down";
            this.SF_Down.Size = new System.Drawing.Size(22, 22);
            this.SF_Down.Tag = "down";
            this.SF_Down.ToolTipText = "Move Item Down";
            this.SF_Down.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SF_UpDown_MouseUp);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.toolStripRearrangeFolders);
            this.panel1.Location = new System.Drawing.Point(170, 18);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(25, 53);
            this.panel1.TabIndex = 7;
            // 
            // FrmRearrangeFolderPositions
            // 
            this.AcceptButton = this.OKBtn;
            this.ClientSize = new System.Drawing.Size(293, 233);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.CancelBtn);
            this.Controls.Add(this.OKBtn);
            this.Controls.Add(this.SongFolder);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmRearrangeFolderPositions";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Re-Arrange Song Folders";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmRearrangeFolderPositions_FormClosing);
            this.Load += new System.EventHandler(this.FrmRearrangeFolderPositions_Load);
            this.toolStripRearrangeFolders.ResumeLayout(false);
            this.toolStripRearrangeFolders.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		public FrmRearrangeFolderPositions()
		{
			this.InitializeComponent();
		}
		private void FrmRearrangeFolderPositions_Load(object sender, EventArgs e)
		{
			this.BuildFolderList();
		}
		private void BuildFolderList()
		{
			ListViewItem listViewItem = new ListViewItem();
			this.SongFolder.Items.Clear();
			for (int i = 1; i < 41; i++)
			{
				listViewItem = this.SongFolder.Items.Add(gf.FolderName[i]);
				listViewItem.SubItems.Add(i.ToString());
			}
		}
		private void SF_UpDown_MouseUp(object sender, MouseEventArgs e)
		{
			ToolStripButton toolStripButton = (ToolStripButton)sender;
			string name = toolStripButton.Name;
			if (name == "SF_Up")
			{
				this.MoveFolderUp();
			}
			else
			{
				this.MoveFolderDown();
			}
		}
		private void MoveFolderUp()
		{
			int count = this.SongFolder.Items.Count;
			if (count >= 1)
			{
				int selectedIndex = gf.GetSelectedIndex(this.SongFolder);
				if (selectedIndex >= 1)
				{
					for (int i = 0; i <= 1; i++)
					{
						string text = this.SongFolder.Items[selectedIndex].SubItems[i].Text;
						this.SongFolder.Items[selectedIndex].SubItems[i].Text = this.SongFolder.Items[selectedIndex - 1].SubItems[i].Text;
						this.SongFolder.Items[selectedIndex - 1].SubItems[i].Text = text;
					}
					this.SongFolder.Items[selectedIndex].Selected = false;
					this.SongFolder.Items[selectedIndex - 1].Selected = true;
					this.SongFolder.EnsureVisible(selectedIndex - 1);
				}
			}
		}
		private void MoveFolderDown()
		{
			int count = this.SongFolder.Items.Count;
			if (count > 1)
			{
				int selectedIndex = gf.GetSelectedIndex(this.SongFolder);
				if (!(selectedIndex < 0 | selectedIndex == count - 1))
				{
					for (int i = 0; i <= 1; i++)
					{
						string text = this.SongFolder.Items[selectedIndex].SubItems[i].Text;
						this.SongFolder.Items[selectedIndex].SubItems[i].Text = this.SongFolder.Items[selectedIndex + 1].SubItems[i].Text;
						this.SongFolder.Items[selectedIndex + 1].SubItems[i].Text = text;
					}
					this.SongFolder.Items[selectedIndex].Selected = false;
					this.SongFolder.Items[selectedIndex + 1].Selected = true;
					this.SongFolder.EnsureVisible(selectedIndex + 1);
				}
			}
		}
		private void OKBtn_Click(object sender, EventArgs e)
		{
			this.Cursor = Cursors.WaitCursor;
			string inName = gf.FolderName[gf.JumpToA];
			string inName2 = gf.FolderName[gf.JumpToB];
			string inName3 = gf.FolderName[gf.JumpToC];
			if (gf.SwapFolderNumbers(this.SongFolder))
			{
				gf.LoadFolderNamesArray();
				gf.JumpToA = gf.GetFolderNumber(inName);
				gf.JumpToB = gf.GetFolderNumber(inName2);
				gf.JumpToC = gf.GetFolderNumber(inName3);
				base.DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("Error encountered whilst re-arranging some of the folders. Please restart EasiSlides and try again.");
				base.DialogResult = DialogResult.Cancel;
			}
			this.Cursor = Cursors.Default;
			base.Close();
		}
		private void FrmRearrangeFolderPositions_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.Cursor = Cursors.Default;
		}

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            base.Close();
        }
	}
}
